


package com.gc.server.controller;
import com.gc.server.enums.AdviseStatusEnum;
import com.gc.server.enums.CostApplyStatusEnum;
import com.yf.request.SearchParam;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.gc.server.vo.AdviseVo;
import com.gc.server.service.AdviseService;
import com.yf.response.R;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
                
/**
 * 建议Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Thu Oct 22 09:25:43 CST 2020
 */
@RestController
@RequestMapping("/advise")
public class AdviseController {
    @Autowired
    private AdviseService adviseService;

    /**
     * 列表建议
     */
    @SysLog("查看建议")
    @RequestMapping("/list")
    @RequiresPermissions("advise:list")
    public R list(@RequestBody SearchParam<AdviseVo> params) {
        PageHelper.startPage(params.getPage(), params.getLimit()).setOrderBy(params.getOrder());
        List<AdviseVo> list = adviseService.findVo(params.getEntity());
        return R.ok(new PageInfo(list));
    }

    /**
 * 下载订单
 */
    @SysLog("下载订单")
    @RequestMapping("/down")
    @RequiresPermissions("advise:list")
    public void down(@RequestBody SearchParam<AdviseVo> params, HttpServletResponse response) {
        List<AdviseVo> list = adviseService.findVo(params.getEntity());
            adviseService.downLoad(response, list);
    }


    /**
     * 查看建议
     */
    @SysLog("查看建议")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("advise:info")
    public R info(@PathVariable("id") Long id) {
            AdviseVo vo = adviseService.getVo(id);

        return R.ok(vo);
    }

    /**
     * 保存建议
     */
    @SysLog("保存建议")
    @RequestMapping("/save")
    @RequiresPermissions("advise:save")
    public R save(@RequestBody AdviseVo vo) {
            adviseService.saveVo(vo);
        return R.ok(vo);
    }

    /**
     * 修改建议
     */
    @SysLog("修改建议")
    @RequestMapping("/update")
    @RequiresPermissions("advise:update")
    public R update(@RequestBody AdviseVo vo) {
            adviseService.updateVo(vo);

        return R.ok(vo);
    }

    /**
     * 删除建议
     */
    @SysLog("删除建议")
    @RequestMapping("/delete")
    @RequiresPermissions("advise:delete")
    public R delete(Long[]ids) {
            adviseService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有建议
     */
    @SysLog("所有建议")
    @RequestMapping("/all")
    public R all(String order) {
        PageHelper.orderBy(order!=null ? order : "id desc");
        List<AdviseVo> list = adviseService.findVo(null);
        return R.ok(list);
    }

    /**
     * 所有enums
     */
    @SysLog("所有enums")
    @RequestMapping("/dmz/options")
    public R options() {
        HashMap<String,Object> options = new HashMap();
        options.put("statusOptions", AdviseStatusEnum.names());
        return R.ok(options);
    }





    /***********自定义开始***********/
}
